import Mock from 'mockjs' // 引入mock
var dataList = []
for (var i = 0; i < 51; i++) {
  dataList.push(Mock.mock({
    'id': '@increment',
    'name': '@cname',
    'phone': /^1[0-9]{10}$/,
    'email': '@email',
    'address': '@county(true)',
    'createTime': '@date("yyyy-MM-dd")'
  }))
}
//开始的位置 size 每页显示的条数 list 总结数据
function pagination(currentPage, pageSize, list) {
  // index = 2 size 10   list.slice(10,20)
  return list.slice((currentPage-1)*pageSize, currentPage*pageSize)
}
// 获取用户列表   接收ajax请求的接口
Mock.mock(new RegExp('/user/list'), 'post', (opts) => {
  var list =dataList;
  console.log(opts.body)
  var currentPage = JSON.parse(opts.body).currentPage;//当前页
  var pageSize = 10;
  var total = list.length//总条数
  list = pagination(currentPage, pageSize, list)//调用分页函数 返回当前页的数据
  return {  //PageList
    'total': total,
    'rows': list
  }
})
